package http;

import frame.service.standard.Constants;
import org.slf4j.MDC;

import javax.servlet.*;
import java.io.IOException;
import java.util.UUID;

public class MDCHttpFilter implements Filter {
    /**
     * 设置单笔交易UUID，用于日志打印
     * */
    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        String uuid = UUID.randomUUID().toString();
        MDC.put(Constants.LOG_REQUEST_UUID, uuid);
        servletRequest.setAttribute(Constants.REQUEST_UUID, uuid);
        filterChain.doFilter(servletRequest, servletResponse);
    }
}